package jtk.project4.fleet;

import java.sql.SQLException;
import java.util.List;

import jtk.project4.fleet.domain.MiscExp;
import jtk.project4.fleet.domain.TireCfg;
import jtk.project4.fleet.domain.Customers;
import jtk.project4.fleet.domain.EmployeeC;
import jtk.project4.fleet.domain.Fluids;
import jtk.project4.fleet.domain.Fuel;
import jtk.project4.fleet.domain.FuelRec;
import jtk.project4.fleet.domain.History;
import jtk.project4.fleet.domain.Invoices;
import jtk.project4.fleet.domain.MeterLog;
import jtk.project4.fleet.domain.Odometer;
import jtk.project4.fleet.domain.Payments;
import jtk.project4.fleet.domain.PmHist;
import jtk.project4.fleet.domain.Po;
import jtk.project4.fleet.domain.TireInv;
import jtk.project4.fleet.domain.PoD;
import jtk.project4.fleet.domain.FuelTank;
import jtk.project4.fleet.domain.Vendor;
import jtk.project4.fleet.domain.Employee;
import jtk.project4.fleet.domain.PartHist;
import jtk.project4.fleet.ibatis.dao.PartHistDao;
import jtk.project4.fleet.ibatis.dao.CustomersDao;
import jtk.project4.fleet.ibatis.dao.FluidsDao;
import jtk.project4.fleet.ibatis.dao.FuelDao;
import jtk.project4.fleet.ibatis.dao.FuelRecDao;
import jtk.project4.fleet.ibatis.dao.MiscExpDao;
import jtk.project4.fleet.ibatis.dao.PmHistDao;
import jtk.project4.fleet.ibatis.dao.PoDao;
import jtk.project4.fleet.ibatis.dao.TireInvDao;
import jtk.project4.fleet.ibatis.dao.VendorsDao;
import jtk.project4.fleet.ibatis.dao.EmployeesDao;
import nl.coderight.jazz.form.FormModel;

public class FleetModel<Public> extends FormModel{
	private List<Vendor> vendors;
	//private List<Employee> employees;
	private List<Odometer> odometers ;
	private Odometer odometer;

	private List<Customers> customers;
	private List<Po> pos;
	private List<History> histories;
	private List<Employee> employees;
	private Po po;
	private Customers customer;
	private Vendor vendor;
	private History history;
	private Employee employee;
	private List<TireInv> tireInvs;
	private TireInv tireInv;
	private List<MeterLog> meterLogs;
	private MeterLog meterLog;
	private List<TireCfg> tirecfgs;
	private TireCfg tirecfg;
	private List<Invoices> invoices;
	private Invoices invoice;
	private List<Payments> payments;
	private Payments payment;
	private List<PmHist> pmHists;
	private List<PoD> poDs;
	private PoD poD;
	private List<FuelRec> fuelrecs;
	private FuelRec fuelrec;
	private Fuel fuel;
	private List<Fuel> fuels;
	private List<Fluids> fluids;
	private Fluids fluid;
	private List<MiscExp> miscexps;
	private MiscExp miscExp;
	private List<FuelTank> fuelTanks;
	private FuelTank fuelTank;
   private PartHist partHist;
	

	//List pmHist tidak perlu digunakan dahulu
	private PmHist pmHist;
	
	private List<EmployeeC> employeecs; 
	private EmployeeC employeec;
	
	public List<Vendor> getVendors() {
		return vendors;
	}

	public void setVendors(List<Vendor> vendors) {
		this.vendors = vendors;
		notifyValueChanged("vendors", vendors);		
	}
	
	public Vendor getVendor() {
		return vendor;
	}

	public void setVendor(Vendor vendor) {
		this.vendor = vendor;
		notifyValueChanged("vendor", vendor);
	}

	public Vendor createVendor() {
		Vendor vendor = new Vendor();
		setVendor(vendor);
		return vendor;
	}
   
   public PartHist getPartHist() {
		return partHist;
	}
	
	public void setPartHist(PartHist partHist) {
		this.partHist = partHist;
		notifyValueChanged("partHist", partHist);
	}
	
	public PartHist createPartHist(){
		PartHist partHist = new PartHist();
		setPartHist(partHist);
		return partHist;
	}
	
	public void insertPartHist(PartHist partHist) throws SQLException {
		new PartHistDao().insertPartHists(partHist);
	}
	
	public void insertOrUpdateVendor(Vendor vendor) throws SQLException {
		if (vendor.getVendorID() == null) {
			new VendorsDao().insertVendor(vendor);
			new VendorsDao().insertVendorType(vendor);
			vendors.add(vendor);
			notifyValueInserted("vendors", vendor);
		} else {
			new VendorsDao().updateVendor(vendor);
			new VendorsDao().insertVendorType(vendor);
			notifyValueUpdated("vendors", vendor);
		}
	}

	public void deleteVendor(Vendor vendor) throws SQLException {
		vendors.remove(vendor);
		new VendorsDao().deleteVendor(vendor);
		notifyValueDeleted("vendors", vendor);
		
	}


	public void setEmployeess(Employee employeess) {
		this.employee= employeess;
	}

	public Employee getEmployeess() {
		return employee;
	}

	public void insertEmployees(Employee employees) throws SQLException{
		new EmployeesDao().insertEmployees(employee);
		
	}
	
	public Employee createEmployee(){
		Employee employeess = new Employee();
		setEmployee(employee);
		return employeess;
	}

	

	

	
	public void insertPmHist(PmHist pmHist) throws SQLException {
		new PmHistDao().insertPmHist(pmHist);
	}

	public void setCustomer(Customers customer) {
		this.customer = customer;
	}

	public Customers getCustomer() {
		return customer;
	}

	public void setCustomers(List<Customers> customers) {
		this.customers = customers;
	}

	public List<Customers> getCustomers() {
		return customers;
	}
	
	public void insertOrUpdateCustomer(Customers customer) throws SQLException {
		System.out.println("demi alek");
		if (customer.getVendorId() == null) {
			//System.out.println("demi alek");
			new CustomersDao().insertCustomers(customer);
			//new CustomersDao().insertCustomersType(customer);
			customers.add(customer);
			notifyValueInserted("customers", customer);
		} else {
			new CustomersDao().updateCustomers(customer);
			//new CustomersDao().insertCustomersType(customer);
			notifyValueUpdated("customers", customer);
		}
	}
	public Customers createCustomers() {
		Customers customer = new Customers();
		setCustomer(customer);
		return customer;
	}
	
	public void insertCustomers(Customers customers) throws SQLException{
		new CustomersDao().insertCustomers(customers);
	}
	public void deleteCustomers(Customers customer) throws SQLException {
		customers.remove(customer);
		//vendors.remove(vendor);
		new CustomersDao().deleteCustomers(customer);
		notifyValueDeleted("customers", customer);
		
	}
	
	public void setPmHists(List<PmHist> pmHists) {
		this.pmHists = pmHists;
	}

	public List<PmHist> getPmHists() {
		return pmHists;
	}

	public void setPmHist(PmHist pmHist) {
		this.pmHist = pmHist;
	}

	public PmHist getPmHist() {
		return pmHist;
	}
	
	public PmHist createPmHist(){
		PmHist pmHist = new PmHist();
		setPmHist(pmHist);
		return pmHist;
	}

	public void setPos(List<Po> pos) {
		this.pos = pos;
	}

	public List<Po> getPos() {
		return pos;
	}

	public void setPo(Po po) {
		this.po = po;
	}

	public Po getPo() {
		return po;
	}
	
	public Po createPo() 
	{
		Po po = new Po();
		setPo(po);
		return po;
	}
	
	public void insertPo(Po po) throws SQLException {
		new PoDao().insertPo(po);
	}

	public void setHistories(List<History> histories) {
		this.histories = histories;
	}

	public List<History> getHistories() {
		return histories;
	}

	public void setHistory(History history) {
		this.history = history;
	}

	public History getHistory() {
		return history;
	}
	
	public void setEmployees(List<Employee> employees) {
		this.employees = employees;
	}
	
	public List<Employee> getEmployees() {
		return employees;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public Employee getEmployee() {
		return employee;
	}
	public void insertOrUpdateTireInv(TireInv tireInv) throws SQLException {
		if (tireInv.getTireId() == null) {
			System.out.println("\ninsertOrUpdateTireInv : " + tireInv.getSerialNo());
			new TireInvDao().insertTireInv(tireInv);
			new TireInvDao().insertTireStatus(tireInv);
			tireInvs.add(tireInv);
			notifyValueInserted("tireInvs", tireInv);
		} else {
			new TireInvDao().updateTireInv(tireInv);
			new TireInvDao().insertTireStatus(tireInv);
			notifyValueUpdated("tireInvs", tireInv);
		}
		System.out.println("\ninsertupdateTireinv : " + tireInv.getSerialNo());
	}
	
	public void setTireInv(TireInv tireInv) {
		this.tireInv = tireInv;
		notifyValueChanged("tireInv", tireInv);
		System.out.println("\nsetTireInv : " + this.tireInv.getSerialNo());
	}
	
	public TireInv createTireInv() {
		TireInv tireInv = new TireInv();
		setTireInv(tireInv);
	
		return tireInv;
	}

	public void setTireInvs(List<TireInv> tireInvs) {
		this.tireInvs = tireInvs;
		notifyValueChanged("tireInvs", tireInvs);		

	}

	public List<TireInv> getTireInvs() {
		return tireInvs;
	}


	public TireInv getTireInv() {
		return tireInv;
	}

	public void deleteTireInv(TireInv tireInv) throws SQLException {
		tireInvs.remove(tireInv);
		new TireInvDao().deleteTireInv(tireInv);
		notifyValueDeleted("tireInvs", tireInv);
		
	}


	public void setMeterLogs(List<MeterLog> meterLogs) {
		this.meterLogs = meterLogs;
	}

	public List<MeterLog> getMeterLogs() {
		return meterLogs;
	}

	public void setMeterLog(MeterLog meterLog) {
		this.meterLog = meterLog;
	}

	public MeterLog getMeterLog() {
		return meterLog;
	}

	public void setEmployeecs(List<EmployeeC> employeecs) {
		this.employeecs = employeecs;
	}

	public List<EmployeeC> getEmployeecs() {
		return employeecs;
	}

	public void setEmployeec(EmployeeC employeec2) {
		this.employeec = (EmployeeC) employeec2;
	}

	public EmployeeC getEmployeec() {
		return employeec;
	}
	
	public EmployeeC createEmployeeC() {
		EmployeeC employeeC= new EmployeeC();
		setEmployeec(employeec);
		return employeeC;
	}
	

	public void setTirecfgs(List<TireCfg> tirecfgs) {
		this.tirecfgs = tirecfgs;
		notifyValueChanged("tirecfgs", tirecfgs);
	}

	public List<TireCfg> getTirecfgs() {
		return tirecfgs;
	}

	public void setTirecfg(TireCfg tirecfg) {
		this.tirecfg = tirecfg;
		notifyValueChanged("tirecfg", tirecfg);
	}

	public TireCfg getTirecfg() {
		return tirecfg;
	}
	public TireCfg createTirecfg() {
		TireCfg tirecfg = new TireCfg();
		setTirecfg(tirecfg);
		return tirecfg;
	}

	public List<Invoices> getInvoices() {
		return invoices;
	}

	public void setInvoices(List<Invoices> invoices) {
		this.invoices = invoices;
		notifyValueChanged("Invoices", invoices);		
	}
	
	public Invoices getInvoice() {
		return invoice;
	}

	public void setInvoice(Invoices invoice) {
		this.invoice = invoice;
		notifyValueChanged("Invoice", invoice);
	}

	public Invoices createInvoice() {
		Invoices invoice = new Invoices();
		setInvoice(invoice);
		return invoice;
	}
	
	public List<Payments> getPayments() {
		return payments;
	}

	public void setPayments(List<Payments> payments) {
		this.payments = payments;
		notifyValueChanged("Payments", payments);		
	}
	
	public Payments getPayment() {
		return payment;
	}

	public void setPayment(Payments payment) {
		this.payment = payment;
		notifyValueChanged("Payments", payment);
	}

	public Payments createPayment() {
		Payments payment = new Payments();
		setPayment(payment);
		return payment;
	}

	public PoD getPoD() {
		return poD;
	}
	
	public void setPoD(PoD poD) {
		this.poD = poD;
		notifyValueChanged("poD", poD);
	}
	
	public PoD createPoD() {
		PoD poD = new PoD();
		setPoD(poD);
		return poD;
	}
	
	public void setPoDs(List<PoD> poDs) {
		this.poDs = poDs;
		notifyValueChanged("poDs", poDs);		
	}

	public List<PoD> getPoDs() {
		return poDs;
		
	}
	
	public void setFuelrecs(List<FuelRec> fuelrecs) {
		this.fuelrecs = fuelrecs;
	}

	public List<FuelRec> getFuelrecs() {
		return fuelrecs;
	}
	
	public void setFuelrec(FuelRec fuelrec) {
		this.fuelrec = fuelrec;
	}

	public FuelRec getFuelrec() {
		return fuelrec;
	}
	
	public void insertFuelRec(FuelRec fuelRec) throws SQLException {
		new FuelRecDao().insertFuelRec(fuelRec);
	}
	
	public FuelRec createFuelRec(){
		FuelRec fuelrec = new FuelRec();
		setFuelrec(fuelrec);
		return fuelrec;
	}
	
	
	public void setOdometer(Odometer list) {
		this.odometer = list;
		notifyValueDeleted("odometer", odometer);
		
	}

	public Odometer getOdometer() {
		return odometer;
	}

	public void setOdometers(List<Odometer> odometers) {
		this.odometers = odometers;
		notifyValueDeleted("odometers", odometers);
		
	}

	public List<Odometer> getOdometers() {
		return odometers;
	}
	
	public Odometer createOdometer() {
		Odometer odometer = new Odometer();
		setOdometer(odometer);
		return odometer;
	}
	/*public void insertTireCfg(TireCfg tirecfg) throws SQLException {
	//new TireCfgDao().insertTireCfg(tirecfg);
	}

	
	public void deleteTireCfg(TireCfg tirecfg) throws SQLException {
		tirecfgs.remove(tirecfg);
		//new TireCfgDao().deleteTireCfg(tirecfg);
		notifyValueDeleted("tirecfgs", tirecfg);
		*/
	
	public void insertFuel(Fuel fuel) throws SQLException {
		new FuelDao().insertFuel(fuel);
	
	}
	public void setFuel(Fuel fuel) {
		this.fuel = fuel;
	}

	public Fuel getFuel() {
		return fuel;
	}
	public Fuel createFuel(){
		Fuel fuel = new Fuel();
		setFuel(fuel);
		System.out.println("DEMI ALEK");
		return fuel;
	}
	
	public void insertFluids(Fluids fluid) throws SQLException {
		new FluidsDao().insertFluids(fluid);
	
	}

	public void setFluids(Fluids fluid) {
		this.fluid = fluid;
	}

	public Fluids getFluids() {
		return fluid;
	}
	public Fluids createFluids(){
		Fluids fluid = new Fluids();
		setFluids(fluid);
		System.out.println("DEMI ALEK");
		return fluid;
	}
	
	public void insertMiscExp(MiscExp miscExp) throws SQLException {
		new MiscExpDao().insertMiscExp(miscExp);
	
	}

	public void setMiscExp(MiscExp miscExp) {
		this.miscExp = miscExp;
	}

	public MiscExp getMiscExp() {
		return miscExp;
	}
	public MiscExp createMiscExp(){
		MiscExp miscExp = new MiscExp();
		setMiscExp(miscExp);
		System.out.println("DEMI ALEK");
		return miscExp;
	}
	public FuelTank createFuelTank() {
		// TODO Auto-generated method stub
		FuelTank fuelTank = new FuelTank();
		setFuelTank(fuelTank);
	
		return fuelTank;
	}

	private void setFuelTank(FuelTank fuelTank) {
		// TODO Auto-generated method stub
		this.fuelTank = fuelTank;		
	}

	public void setFuelTanks(List<FuelTank> fuelTanks) {
		this.fuelTanks = fuelTanks;
		notifyValueChanged("fuelTanks", fuelTanks);		

	}

	public List<FuelTank> getFuelTanks() {
		return fuelTanks;
	}


	public FuelTank getFuelTank() {
		return fuelTank;
	}
	public void insertFuelTank(FuelTank fuelTank) throws SQLException {
		new FuelTankDao().insertFuelTank(fuelTank);
		
	}
}

